package com.roc.util.constant;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * 
 * @author zx-think
 *
 */
public enum RecodeType {
	

	FLAG_04("04","没收卡"),
	FLAG_05("05","不予承兑"),
	//FLAG_34("34","有作弊嫌疑"),
	FLAG_41("41","丢失卡"),
	FLAG_43("43","被窃卡"),
	FLAG_54("54","过期的卡"),
	FLAG_59("59","有作弊嫌疑"),
	FLAG_X1("XX1","日交易累计3笔以上"),
	FLAG_X2("XX2","日累计2W"),
	FLAG_X3("XX3","月累计3W"),
	FLAG_X4("XX4","单笔1w");
	

	private String code;
	private String name;
	
	private RecodeType(String code,String name){
		this.code=code;
		this.name=name;
	}
	
	public static RecodeType valueOfCode(String code) {
		if (StringUtils.isBlank(code)) {
			throw new IllegalArgumentException("Merchant Status " + code
					+ " is blank");
		}
		for (RecodeType mt : values()) {
			if (mt.getCode().equals(code)) {
				return mt;
			}
		}
		throw new IllegalArgumentException("Merchant Type " + code
				+ " is not exist");
	}
	
	/**
	 * 通过ID获取中文名称
	 * @param code
	 * @return
	 */
	public static String getName(String code) {
		if (StringUtils.isBlank(code)) {
			throw new IllegalArgumentException("MerberFlag code " + code
					+ " is blank");
		}
		for (RecodeType mt : values()) {
			if (mt.getCode().equals(code)) {
				return mt.getName();
			}
		}
		throw new IllegalArgumentException("MerberFlag code  " + code
				+ " is not exist");
	}
	
	/**
	 * 获取所有的枚举,以MAP返回
	 * @return
	 */
	public static Map<String,String> getAllEnumMap() {
		
		Map<String,String> map = new LinkedHashMap<String,String>();
		
		for (RecodeType mt : values()) {
			map.put(mt.getCode(), mt.getName());
		}
		
		return map;
		
	}
	
	
	public static String getAllCode(){
		
		
		StringBuffer sb = new StringBuffer();
		
		for (RecodeType mt : values()) {
			sb.append("'"+mt.getCode()+"'");
			sb.append(",");
		}
		
		String a = sb.toString();
		
		return a.substring(0, a.length()-1);
		
	}
	
	public String getCode() {
		return code;
	}

	public String getName() {
		return name;
	}
	
}
